home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_15_1987_Transactor_Publishing.d64
/
freq cntr.pal
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2023-02-26
|
2KB
|
97 lines
100 rem open 1,8,1,"@0:freq.cntr.@c000" :rem file for object code
110 sys 700 ;pal 64 assembler
120 .opt oo
130 ; save"@0:freq cntr.pal",8
140 ;----------------------------------
150 ;- frequency counter -
160 ;- source code -
170 ;----------------------------------
180 ; uses cia #2, timer a
190 ; count is stored at 680, 681
200 ; gate value is stored at 822
210 ; overflow sets 823
220 ;.opt o1 ;sends object code to disk
230 ;
240 *=$c000 ;start address
250 ;sys 49152-to start counting
260 ;sys 49155-to stop counting and disable interrupt wedge
270 ;system equates
280 cia2 =$dd00
290 talo =cia2+$04;timer a count registers
300 tahi =cia2+$05
310 icr =cia2+$0d;cia interrupt control register
320 cra =cia2+$0e;cia control register
330 oldirq =$0334 ;storage for old irq
340 irqvec =$0314
350 flag =679
360 count =680
370 gate =$0336 ;storage for count down value
380 overflow =823
390 ;
400 jmp connect
410 ;disconnect routine
420 sei
430 lda oldirq ;put old irq vector back
440 sta irqvec ; in
450 lda oldirq+1
460 sta irqvec+1
470 lda #$00
480 sta cra ;stop timer
490 cli
500 rts
510 ;
520 connect =*
530 sei ;disable interrupts
540 lda irqvec
550 sta oldirq ;store old irq vector
560 lda irqvec+1
570 sta oldirq+1
580 lda #<start ;point to our routine
590 sta irqvec
600 lda #>start ;same with high byte
610 sta irqvec+1
620 lda #$ff
630 sta talo
640 sta tahi ;load timer latch with maximum count
650 lda #60
660 sta gate ;use a default value of 60
670 lda gate ;get count-down value
680 sta flag ;put it in the flag register
690 lda #$00
700 sta icr ;disable cia interupts
710 lda #%00110001
720 sta cra ;force load and start counting
730 cli
740 rts ;all done so return
750 ;
760 ;counter routine starts here
770 start =*
780 ;
790 dec flag ;check countdown flag
800 bne done ;not timed out so exit
810 getcnt =* ;routine to read count
820 lda gate
830 sta flag ;reset flag for next time
840 lda #%00100000 ;set bit 5
850 sta cra ;to stop timer
860 lda talo
870 eor #$ff
880 sta count ;convert to up-counter and store result
890 lda tahi
900 eor #$ff
910 sta count+1 ;same with high byte
920 lda #$ff
930 sta talo
940 sta tahi ;reset timer latch
950 lda #%00110001 ;force load + start timer
960 sta cra
970 lda icr
980 and #%00000011 ;mask off upper 6 bits of status register
990 sta overflow ;and save it
1000 ;
1010 ;
1020 done =*
1030 jmp (oldirq) ;(NULL) to normal irq routine
1040 ;
1050 .end